package com.proxy;


import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class TestDemo {
    public static void main(String[] args) {
        Car car = new WLCar();
        car.run(10000.0);
        car.stop();
        System.out.println("-------------------");
        Car proxy_car = (Car) Proxy.newProxyInstance(car.getClass().getClassLoader(), car.getClass().getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                if("run".equals(method.getName())){
                    System.out.println("五菱弹射起步……"+args[0]);
                    return null;
                }else {
                    return method.invoke(car,args);
                }
            }
        });
        proxy_car.run(10000.0);
        proxy_car.stop();
    }
}
